<!--这是活动详情组件-->
<style>
.el-input-group--prepend .el-input__inner,
.el-input-group__append {
  padding: 0px 10px;
}
</style>
<template>
  <div class="app-container">
    <el-form
      v-show="isBasicInfo"
      v-loading="formLoading"
      :model="postForm.basicInfo"
      :rules="rules"
      ref="basicInfo"
      label-width="220px"
      label-position="right"
    >
      <div class="font-family-h font-bold margin-t50 margin-b40">
        <i class="square"></i>基础信息
      </div>
      <el-form-item label="活动名称：" prop="name">
        <el-input
          :disabled="postForm.basicInfo.state==2"
          :maxlength="40"
          v-model="postForm.basicInfo.name"
          placeholder="请输入活动名称"
          style="width: 650px"
        ></el-input>
      </el-form-item>
      <el-form-item label="活动地点：" prop="place">
        <el-input
          :disabled="postForm.basicInfo.state==2"
          :maxlength="40"
          v-model="postForm.basicInfo.place"
          placeholder="请输入活动名称"
          style="width: 650px"
        ></el-input>
      </el-form-item>
      <el-form-item label="活动主办方：" prop="sponsor">
        <el-input
          :disabled="postForm.basicInfo.state==2"
          :maxlength="40"
          v-model="postForm.basicInfo.sponsor"
          placeholder="请输入主办方"
          style="width: 650px"
        ></el-input>
      </el-form-item>
      <el-form-item label="选择分类：" prop="sponsor">
        <el-select v-model="postForm.basicInfo.catId" placeholder="请选择">
          <el-option
            v-for="item in optionsList"
            :key="item.catId"
            :label="item.name"
            :value="item.catId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="浏览人数基数：">
        <el-input-number
          v-model="postForm.basicInfo.virtualBrowse"
          placeholder="请输入浏览人数基数"
          style="width: 300px"
        ></el-input-number>
      </el-form-item>
      <el-form-item label="受众人群：">
        <el-input
          :maxlength="40"
          v-model="postForm.basicInfo.audience"
          placeholder="请输入对象"
          style="width: 650px"
        ></el-input>
      </el-form-item>
      <el-form-item label="是否显示报名人数：">
        <el-radio-group v-model="postForm.basicInfo.showEnroll">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <!--<el-form-item label="是否开通邀请卡：">-->
      <!--<el-select v-model="postForm.basicInfo.isInvitionCard" placeholder="请选择" style="width: 650px"-->
      <!--@change="inviteSelect">-->
      <!--<el-option v-for="item in inviteOptions" :key="item.key" :label="item.value" :value="item.key"></el-option>-->
      <!--</el-select>-->
      <!--</el-form-item>-->
      <!-- <el-form-item label="是否开通邀请卡:">
        <el-radio-group v-model="postForm.basicInfo.isInvitionCard">
          <el-radio :disabled="postForm.basicInfo.state==2" :label="0">否</el-radio>
          <el-radio :disabled="postForm.basicInfo.state==2" :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>-->
      <el-form-item label="开始报名时间：" prop="signTime">
        <el-radio-group v-model="postForm.basicInfo.enroll_at_type" @change="selectEnrollType">
          <el-radio :disabled="postForm.basicInfo.state==2" :label="0">默认为活动发布后至活动开始前</el-radio>
          <el-radio :disabled="postForm.basicInfo.state==2" :label="1">自定义</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="自定义报名时间：" v-if="isShowDefineTime">
        <el-date-picker
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="报名日期（开始）"
          v-model="postForm.basicInfo.enrollStartAt"
          :picker-options="pickerOptions"
          style="width: 300px;"
        ></el-date-picker>
        <span style="padding: 0 10px;font-size: 14px;color: #666;">至</span>
        <el-date-picker
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="报名日期（结束）"
          v-model="postForm.basicInfo.enrollEndAt"
          :picker-options="pickerOptions"
          :disabled="postForm.basicInfo.state==2"
          style="width: 300px;"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="活动时间：">
        <el-date-picker
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="活动日期（开始）"
          v-model="postForm.basicInfo.startAt"
          :disabled="postForm.basicInfo.state==2"
          :picker-options="pickerOptions"
          style="width: 300px;"
        ></el-date-picker>
        <span style="padding: 0 10px;font-size: 14px;color: #666;">至</span>
        <el-date-picker
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="活动日期（结束）"
          v-model="postForm.basicInfo.endAt"
          :picker-options="pickerOptions"
          :disabled="postForm.basicInfo.state==2"
          style="width: 300px;"
        ></el-date-picker>
      </el-form-item>

      <!--<el-form-item label="活动海报(宽640*高320)：" prop="activityUpload">-->
      <!--<el-upload-->
      <!--ref="activityUpload"-->
      <!--name="avatar"-->
      <!--:action="imageUploadUrl"-->
      <!--list-type="picture"-->
      <!--:before-upload="handleBeforeUpload"-->
      <!--:on-success="handleActivitySuccess"-->
      <!--:on-remove="handleActivityRemove"-->
      <!--:before-remove="beforeRemove"-->
      <!--:file-list="poster"-->
      <!--:limit="1"-->
      <!--:on-exceed="handleExceed"-->
      <!--:auto-upload="false"-->
      <!--style="width: 420px">-->
      <!--<el-button :disabled="postForm.basicInfo.state==2" slot="trigger" size="small" type="primary">选取文件</el-button>-->
      <!--<el-button style="margin-left: 10px;" size="small" type="success" @click="submitActivityUpload">上传到服务器-->
      <!--</el-button>-->
      <!--</el-upload>        -->
      <!--</el-form-item>-->
      <el-form-item label="活动海报(宽640*高320)：" prop="activityUpload">
        <div class="clearfix">
          <img
            class="fl margin-r"
            :src="postForm.basicInfo.poster"
            @error="setDefultImg"
            width="256"
            height="128"
            alt
          />
          <el-upload
            class="fl"
            ref="activityUpload"
            name="avatar"
            :action="imageUploadUrl"
            list-type="picture"
            :before-upload="handleBeforeUpload"
            :on-success="handleActivitySuccess"
            :on-remove="handleActivityRemove"
            :before-remove="beforeRemove"
            :show-file-list="false"
            :on-exceed="handleExceed"
            :auto-upload="true"
            style="width: 420px"
          >
            <el-button
              :disabled="postForm.basicInfo.state==2"
              slot="trigger"
              size="small"
              type="primary"
            >选取文件</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过3m</div>
          </el-upload>
        </div>
      </el-form-item>
      <el-form-item label="活动详情：">
        <tinymce
          :height="300"
          :disabled="postForm.basicInfo.state==2"
          v-model="postForm.basicInfo.intro"
          style="width: 650px;"
        ></tinymce>
      </el-form-item>
      <!-- <div class="font-family-h font-bold margin-t50 margin-b40">
        <i class="square"></i>代理商分成
      </div>

      <table border="1" cellspacing="0" cellpadding="0" style="width:600px;height:200px;border-color:#999">
        <tr align="center">
          <td></td>
          <td>一级抽成比例</td>
          <td>二级抽成比例</td>
        </tr>
        <tr align="center">
          <td>合伙人</td>
          <td>
            <el-input-number v-model="postForm.basicInfo.agentRatio"></el-input-number>
          </td>
          <td>
            <el-input-number v-model="postForm.basicInfo.agentRatios"></el-input-number>
          </td>
        </tr>
        <tr align="center">
          <td>事业部</td>
          <td>
            <el-input-number v-model="postForm.basicInfo.partnerRatio"></el-input-number>
          </td>
          <td>
            <el-input-number v-model="postForm.basicInfo.partnerRatios"></el-input-number>
          </td>
        </tr>
      </table>-->
      <!-- <p class="margin-b40 margin-t50 font-family-h font-bold"><i class="square"></i>抽成设置<span class="point">(抽成比例总和勿大于100%，即:收益人抽成比例+一级抽成比例+二级抽成比例+三级抽成比例+代理商抽成比例+合伙人抽成比例+分公司抽成比例小于等于100%)</span>
      </p>
     
      <el-form-item label="是否关联收益人:">
        <el-radio-group v-model="hasTeacher" @change="isTeacherSelect">
          <el-radio :disabled="postForm.basicInfo.state==2" :label="-1">否</el-radio>
          <el-radio :disabled="postForm.basicInfo.state==2" :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="选择收益人：" v-show="teacherShow">
        <multiselect :disabled="postForm.basicInfo.state==2" style='width:420px;' v-model="teacherInfo" :options="teacherList" track-by="userId"
                     label="nickname"
                     placeholder="搜索收益人" selectLabel="选择" deselectLabel="删除" @search-change="syncSearchTeachers"
                     @select="teacherOptionSelect" :loading="syncLoading" :internal-search="false">
          <span slot='noResult'>无结果</span>
        </multiselect>
      </el-form-item>
      <el-form-item label="收益人抽成比例" v-show="teacherShow">
        <el-input :disabled="postForm.basicInfo.state==2" type='number' style="width:150px" v-model="postForm.basicInfo.teacherRatio"></el-input>
        %
      </el-form-item>
      <el-form-item label="第一级别抽成(单位%)：">
        <el-table :data="stage1" border style="width: 650px">
          <el-table-column label="第一级抽成比例">
            <template slot-scope="scope">
              <el-input min="0" :disabled="postForm.basicInfo.state==2" type='number' v-model="postForm.basicInfo.l1Ratio" placeholder="第一级抽成比例"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="第二级抽成比例">
            <template slot-scope="scope">
              <el-input min="0" :disabled="postForm.basicInfo.state==2" type='number' v-model="postForm.basicInfo.l2Ratio" placeholder="请输入第二级抽成比例"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="第三级抽成比例">
            <template slot-scope="scope">
              <el-input min="0" :disabled="postForm.basicInfo.state==2" type='number' v-model="postForm.basicInfo.l3Ratio" placeholder="请输入第二级抽成比例"></el-input>
            </template>
          </el-table-column>
      </el-table>-->
      <!-- <el-input v-model="postForm.firstStage" placeholder="第一级抽成比例" style="width:650px"></el-input> -->
      <!-- </el-form-item>
      <el-form-item label="服务商抽成比例(单位%)：" v-if="this.agentLevel > 0">
        <el-table :data="stage2" border style="width: 650px">
          <el-table-column label="代理商抽成比例">
            <template slot-scope="scope">
              <el-input min="0" :disabled="postForm.basicInfo.state==2" type='number' v-model="postForm.basicInfo.agentRatio" placeholder="代理商抽成比例"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="合伙人抽成比例" v-if="this.agentLevel == 3">
            <template slot-scope="scope">
              <el-input min="0" :disabled="postForm.basicInfo.state==2" type='number' v-model="postForm.basicInfo.partnerRatio" placeholder="合伙人抽成比例"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="分公司抽成比例" v-if="this.agentLevel ==3">
            <template slot-scope="scope">
              <el-input min="0" :disabled="postForm.basicInfo.state==2" type='number' v-model="postForm.basicInfo.branchRatio" placeholder="分公司抽成比例"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
      <div v-if="relaShow" class="font-family-h font-bold margin-t50 margin-b40"><i class="square"></i>关联信息</div>
      <el-form-item v-if="datumShow" label="关联资料:">
        <div class="clearfix c-width60 b-c" v-for="(item,index) in postForm.basicInfo.datumArr" :key="index+'|1'">
          <div class="fl">{{item.name}}</div>
          <b class="fr" @click="cancelRel(1, index)">取消关联</b>
        </div>
        <el-button :disabled="postForm.basicInfo.datumArr.length==5||postForm.basicInfo.state==2" @click="addRelObj(1,postForm.basicInfo.datumArr)">
          添加资料
        </el-button>
        <span class="margin-l10 fc">最多可添加5个</span>
      </el-form-item>
      <el-form-item label="关联社群:" v-if="socialShow">
        <div class="clearfix c-width60 b-c" v-for="(item,index) in postForm.basicInfo.socialArr" :key="index+'|2'">
          <div class="fl c-f">{{item.name}}</div>
          <b class="fr" @click.stop.prevent="cancelRel(2, index)">取消关联</b>
        </div>
        <el-button :disabled="postForm.basicInfo.socialArr.length==5||postForm.basicInfo.state==2"
                   @click="addRelObj(2,postForm.basicInfo.socialArr)">添加社群
        </el-button>
        <span class="margin-l10 fc">最多可添加5个</span>
      </el-form-item>
      <el-form-item label="关联测评:" v-if="examShow">
        <div class="clearfix c-width60 b-c" v-for="(item,index) in postForm.basicInfo.examArr" :key="index+'|3'">
          <div class="fl c-f">{{item.name}}</div>
          <b class="fr" @click="cancelRel(3, index)">取消关联</b>
        </div>
        <el-button :disabled="postForm.basicInfo.examArr.length==5||postForm.basicInfo.state==2" @click="addRelObj(3,postForm.basicInfo.examArr)">
          添加测评
        </el-button>
        <span class="margin-l10 fc">最多可添加5个</span>
      </el-form-item>
      <addRelated v-if="isShowAddRelated" :relType="relType" :objData="objData" @saveRelated="saveRelated" @hideAddRelated="hideAddRelated"></addRelated>-->

      <div class="font-family-h font-bold margin-t50 margin-b40">
        <i class="square"></i>分享设置
      </div>
      <!--<el-form-item label="分享公众号标题:">-->
      <!--<el-input :maxlength=26 v-model="postForm.basicInfo.shareTitle"></el-input>-->
      <!--</el-form-item>-->
      <el-form-item label="分享描述:">
        <el-input
          :disabled="postForm.basicInfo.state==2"
          placeholder="分享描述"
          v-model="postForm.basicInfo.shareDesc"
        ></el-input>
      </el-form-item>
      <el-form-item label="分享图片:">
        <div class="clearfix">
          <img
            class="fl margin-r"
            :src="postForm.basicInfo.sharePhoto"
            style="width:150px;height:260px"
            alt
          />
          <el-upload
            class="fl"
            ref="activityUpload"
            name="avatar"
            :action="imageUploadUrl"
            list-type="picture"
            :on-success="handleActivitySuccesss"
            :on-remove="handleActivityRemoves"
            :show-file-list="false"
            :on-exceed="handleExceed"
            :auto-upload="true"
            style="width: 420px"
          >
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过3m</div>
          </el-upload>
        </div>
      </el-form-item>
      <div class="fabu center margin-t60">
        <el-button
          v-loading="btnLoading"
          v-if="postForm.basicInfo.state!=2"
          style="width: 150px;"
          type="primary"
          @click="onPublic"
        >下一步</el-button>
        <el-button v-else style="width: 150px;" type="primary" @click="nextForm">下一步</el-button>
      </div>
    </el-form>
    <el-form
      v-loading="formLoading"
      v-show="isFormSetting"
      :model="postForm.formSetting"
      ref="postForm.formSetting"
      label-width="250px"
      class="demo-dynamic"
    >
      <div class="font-family-h font-bold margin-t50 margin-b40">
        <i class="square"></i>表单设置
      </div>
      <el-form-item
        prop="name"
        label="真实姓名"
        :rules="[
      { required: true, message: '请输入姓名', trigger: 'blur' },
      { type: 'name', message: '请输入正确的姓名', trigger: ['blur', 'change'] }
    ]"
      >
        <el-input disabled style="width:250px"></el-input>
      </el-form-item>
      <el-form-item
        prop="tel"
        label="手机号码"
        :rules="[
      { required: true, message: '请输入手机号码', trigger: 'blur' },
      { type: 'tel', message: '请输入正确的手机号码', trigger: ['blur', 'change'] }
    ]"
      >
        <el-input disabled style="width:250px"></el-input>
      </el-form-item>
      <el-form-item
        prop="tel"
        label="公司全称"
        :rules="[
      { required: true, message: '请输入微信号', trigger: 'blur' },
      { type: 'tel', message: '请输入正确的微信号', trigger: ['blur', 'change'] }
    ]"
      >
        <el-input disabled style="width:250px"></el-input>
      </el-form-item>
      <el-form-item
        prop="tel"
        label="公司职务"
        :rules="[
      { required: true, message: '请输入参与人数', trigger: 'blur' },
      { type: 'tel', message: '请输入正确的参与人数', trigger: ['blur', 'change'] }
    ]"
      >
        <el-input disabled style="width:250px"></el-input>
      </el-form-item>
      <code>
        <svg-icon icon-class="message" style="margin-right:10px;color:red;font-size:20px;"></svg-icon>备注：其他(未添加其他栏位,即不需要报名用户提供其他报名信息)
      </code>
      <el-form-item
        v-for="(item,index) in infos"
        :key="index"
        :label="'自定义字段'+(index+1)"
        v-if="item.deleteStatus==0"
      >
        <div>
          <!-- <span for="" style="width:100px;text-align:right;display:inline-block;margin-right: 30px ;">自定义字段{{index + 1}}:</span> -->
          <el-checkbox
            v-model="item.isReq"
            :checked="item.isReq==1"
            :label="1"
            style="margin-right: 30px"
          >必填</el-checkbox>
          <el-input
            :placeholder="item.isMultiline==0?'单行文本':'多行文本'"
            v-model="item.fieldNo"
            style="width: 150px;"
          ></el-input>
          <el-input
            v-if="item.isMultiline==1"
            type="textarea"
            autosize
            v-model="item.fieldName"
            placeholder="请填写信息"
            style="width: 250px;margin-right:30px"
          ></el-input>
          <el-input
            v-else
            v-model="item.fieldName"
            placeholder="请填写信息"
            style="width: 250px;margin-right:30px"
          ></el-input>
          <el-button type="danger" @click="delInfo(index)">删除</el-button>
        </div>
      </el-form-item>
      <!-- <el-form-item>
        <el-button
          :disabled="postForm.basicInfo.state==2"
          v-if="infos.length<5"
          type="info"
          @click="addSingle"
        >+单行文本</el-button>
        <el-button
          :disabled="postForm.basicInfo.state==2"
          v-if="infos.length<5"
          type="info"
          @click="addMultiline"
        >+多行文本</el-button>
      </el-form-item>-->
      <div class="fabu center margin-t60">
        <el-button style="width: 150px;" type="primary" @click="backBasicInfo">上一步</el-button>
        <el-button style="width: 150px;" type="primary" @click="nextTicket">下一步</el-button>
      </div>
    </el-form>
    <div v-loading="formLoading" v-show="isTicketSetting">
      <div class="font-family-h font-bold margin-t50 margin-b40">
        <i class="square"></i>票务设置
      </div>
      <div class="clearfix margin-t">
        <div class="fl c-width10">免费票</div>
        <div class="fl c-width90">
          <el-form :model="postForm.ticket.freeTicket" class="border" v-show="isFreeTicket">
            <el-row>
              <el-col :span="6" class="margin-l10 margin-r10">
                <div class="padding-tb10 center">票种名称</div>
              </el-col>
              <el-col :span="3">
                <div class="padding-tb10 center">票总数</div>
              </el-col>
              <el-col :span="3" class="margin-l10">
                <div class="padding-tb10 center">价格</div>
              </el-col>
              <el-col :span="3" class="margin-l10">
                <div class="padding-tb10 center">单人购票数(0时不限制单人购票数)</div>
              </el-col>
              <el-col :span="6">
                <div class="padding-tb10 center">操作</div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6" class="margin-l10 margin-r10">
                <el-input v-model="postForm.ticket.name" :maxlength="8" placeholder="限8个字符"></el-input>
              </el-col>
              <el-col :span="3">
                <el-input type="number" v-model="postForm.ticket.number" :min="0"></el-input>
              </el-col>
              <el-col :span="3" class="margin-l10">
                <div class="padding-tb10 center">免费</div>
              </el-col>
              <el-col :span="3" class="margin-l10">
                <el-input type="number" v-model="postForm.ticket.purchaseLimits" :min="0"></el-input>
              </el-col>
              <el-col :span="6">
                <div class="padding-tb10 center">
                  <span class="blue c-cursor-p" @click="conserveFreeTickeData">保存</span>
                  <span class="blue margin-l c-cursor-p" @click="delFreeTicketForm">取消</span>
                </div>
              </el-col>
            </el-row>
            <div class="clearfix margin-t padding-l">
              <div class="fl">票种说明:</div>
              <div class="fl margin-l">
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="postForm.ticket.desc"
                  style="width: 600px;text-align:center;"
                ></el-input>
              </div>
            </div>
            <div class="clearfix margin-t padding-l padding-b10">
              <div class="fl">套票设置:</div>
              <div class="fl margin-l">
                <el-input-number
                  type="number"
                  controls-position="right"
                  v-model="postForm.ticket.taoTicket"
                  style="width:30%"
                  placeholder="输入套票数量"
                  :min="1"
                ></el-input-number>
                <span>设置单次购买票数，可输入 1-100</span>
              </div>
            </div>
            <div class="margin-t padding-l padding-tb20">
              <span class="margin-r">是否需要审核:</span>
              <el-checkbox
                v-model="postForm.ticket.isAudit"
                :checked="postForm.ticket.isAudit==1"
              >报名本活动需要审核</el-checkbox>
            </div>
          </el-form>
          <div v-show="isAdd" class="margin-t10 border-d center padding-tb10 c-cursor-p">
            <el-button
              :disabled="postForm.basicInfo.state==2"
              @click="addFreeTicket"
              type="text"
            >+添加免费票种</el-button>
          </div>
          <el-table
            v-show="freeTicketTableData.length>0"
            :data="freeTicketTableData"
            border
            style="width: 100%"
          >
            <el-table-column prop="name" label="票种名称" width="100"></el-table-column>
            <el-table-column prop="number" label="票总数" width="110"></el-table-column>
            <el-table-column prop="price" label="价格" width="110"></el-table-column>
            <el-table-column prop="isAudit" label="是否审核" width="110">
              <template slot-scope="scope">
                <span>{{scope.row.isAudit == 1 ? '是' : '否'}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="taoTicket" label="套票数量"></el-table-column>
            <el-table-column label="单用户可购" :width="110">
              <template
                slot-scope="scope"
              >{{scope.row.purchaseLimits == 0 ?'不限制' :scope.row.purchaseLimits}}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  :disabled="postForm.basicInfo.state==2"
                  @click="editFreeTicket(scope.$index)"
                  type="text"
                  size="small"
                >编辑</el-button>
                <el-button
                  :disabled="postForm.basicInfo.state==2"
                  type="text"
                  size="small"
                  @click="delFreeTicketData"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div class="clearfix margin-t padding-tb20">
        <div class="fl c-width10">收费票</div>
        <div class="fl c-width90">
          <el-form :model="postForm.ticket.chargeTicket" class="border" v-show="isChargeTicket">
            <el-row>
              <el-col :span="4" class="margin-l10 margin-r10">
                <div class="padding-tb10 center">票种名称</div>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <div class="padding-tb10 center">票总数</div>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <div class="padding-tb10 center">价格</div>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <div class="padding-tb10 center" style="font-size:14px">单人购票数(0时不限制单人购票数)</div>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <div class="padding-tb10 center">是否审核</div>
              </el-col>
              <el-col
                :span="creditShow&&svipShow?3:((creditShow&&!svipShow)||(!creditShow&&svipShow))?5:9"
              >
                <div class="padding-tb10 center">操作</div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="4" class="margin-r10 margin-l10">
                <el-input v-model="postForm.ticket.name" :maxlength="8" placeholder="限8个字符"></el-input>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <el-input type="number" v-model="postForm.ticket.number" :min="0"></el-input>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <el-input type="number" v-model="postForm.ticket.price" :min="0"></el-input>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <el-input-number
                  type="number"
                  controls-position="right"
                  v-model="postForm.ticket.purchaseLimits"
                  style="width:100%"
                  placeholder="0时不限制单人购票数"
                ></el-input-number>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <el-select v-model="postForm.ticket.status" placeholder="是否审核">
                  <el-option label="是" :value="0">是</el-option>
                  <el-option label="否" :value="1">否</el-option>
                </el-select>
              </el-col>
              <!-- <el-col :span="4" v-if="creditShow" class="margin-r10">
                <el-input type="number" v-model="postForm.ticket.deductiblePoints" min="0">
                  <template slot="append">
                    <span class="danwei">元</span>
                  </template>
                </el-input>
              </el-col>
              <el-col :span="3" class="margin-r10">
                <el-input type="number" v-model="postForm.ticket.vipDiscount" min="0" max="100">
                  <template slot="append">
                    <span class="danwei">%</span>
                  </template>
                </el-input>
              </el-col>
              <el-col :span="3" v-if="svipShow">
                <el-input type="number" v-model="postForm.ticket.svipDiscount" min="0" max="100">
                  <template slot="append">
                    <span class="danwei">%</span>
                  </template>
                </el-input>
              </el-col>-->
              <el-col
                :span="creditShow&&svipShow?3:((creditShow&&!svipShow)||(!creditShow&&svipShow))?5:9"
              >
                <div class="padding-tb10 center">
                  <span class="blue c-cursor-p" @click="conserveChargeData">保存</span>
                  <span class="blue margin-l c-cursor-p" @click="delChargeTicketForm">取消</span>
                </div>
              </el-col>
            </el-row>
            <div class="clearfix margin-t padding-l padding-b10">
              <div class="fl">票种说明:</div>
              <div class="fl margin-l">
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="postForm.ticket.desc"
                  style="width: 600px;"
                ></el-input>
              </div>
            </div>
            <div class="clearfix margin-t padding-l padding-b10">
              <div class="fl">套票设置:</div>
              <div class="fl margin-l">
                <el-input-number
                  type="number"
                  controls-position="right"
                  v-model="postForm.ticket.taoTicket"
                  style="width:30%"
                  placeholder="输入套票数量"
                  :min="1"
                ></el-input-number>
                <span>设置单次购买票数，可输入 1-100</span>
              </div>
            </div>
          </el-form>
          <el-table
            v-show="ticketTableData.length>0"
            :data="ticketTableData"
            border
            style="width: 100%"
          >
            <el-table-column prop="name" label="票种名称"></el-table-column>
            <el-table-column prop="number" label="票总数" :width="110"></el-table-column>
            <el-table-column prop="price" label="价格" :width="creditShow?110:140"></el-table-column>
            <el-table-column label="是否要审核" :width="110">
              <template slot-scope="scope">{{scope.row.status == 0 ?'是' :'否'}}</template>
            </el-table-column>
            <el-table-column prop="taoTicket" label="套票数量"></el-table-column>
            <el-table-column label="单用户可购" :width="110">
              <template
                slot-scope="scope"
              >{{scope.row.purchaseLimits == 0 ?'不限制' :scope.row.purchaseLimits}}</template>
            </el-table-column>
            <!-- <el-table-column v-if="creditShow" prop="deductiblePoints" label="积分可抵扣金额"></el-table-column> -->
            <!-- <el-table-column prop="vipDiscount" label="VIP折扣比例"></el-table-column> -->
            <!-- <el-table-column v-if="svipShow" prop="svipDiscount" label="SVIP折扣比例"></el-table-column> -->
            <el-table-column label="操作" width="100">
              <template slot-scope="scope">
                <el-button
                  :disabled="postForm.basicInfo.state==2"
                  type="text"
                  size="small"
                  @click="editTick(scope.$index)"
                >编辑</el-button>
                <el-button
                  :disabled="postForm.basicInfo.state==2"
                  type="text"
                  size="small"
                  @click="delChargeTicketData(scope.$index)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="margin-t10 border-d center padding-tb10 c-cursor-p">
            <el-button
              @click="addChargeTicket"
              :disabled="postForm.basicInfo.state==2"
              type="text"
            >+添加收费票种</el-button>
          </div>
        </div>
      </div>
      <el-form>
        <el-form-item label="是否发布：">
          <el-radio-group v-model="release">
            <el-radio :disabled="postForm.basicInfo.state==2" :label="0">暂不发布</el-radio>
            <el-radio :disabled="postForm.basicInfo.state==2" :label="1">发布</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div class="fabu center margin-t60">
        <el-button style="width: 150px;" type="primary" @click="backFormSetting">上一步</el-button>
        <el-button
          v-loading="finishLoading"
          v-if="postForm.basicInfo.state!=2"
          style="width: 150px;"
          type="primary"
          @click="finish"
        >保存</el-button>
        <el-button type="primary" v-if="postForm.basicInfo.state==2" @click="close">关闭</el-button>
      </div>
    </div>
  </div>
</template>
<script>
// import activeAddRelated from './activeAddRelated.vue'
import addRelated from "@/views/courseColumn/components/addRelated.vue"; // 引入关联组件
import VDistpicker from "v-distpicker"; // 引入城市选择器插件
import Multiselect from "vue-multiselect"; // 引入 vue-multiselect 组件
import "vue-multiselect/dist/vue-multiselect.min.css";
import defultImg from "@/assets/defult270.png";
import Tinymce from "@/components/Tinymce";
import {
  enableSvip,
  getAgentLevels,
  interaction_activities,
  enablePointModule,
  enableDatumModule,
  enableSocialModule,
  enableExamModule
} from "@/utils/permission";
import {
  addOrEditActivities,
  getActivities,
  getActivitiesById,
  getActivityEnrollFields,
  setActivityEnrollFields,
  getActivityTickets,
  getActivityTicketsById,
  setActivityTickets
} from "@/api/activities";
import { catList } from "@/api/activities";
import { getUploadToken } from "@/api/qiniu";
import { getMemberSearch, initMemberList } from "@/api/member";
import { getYmdhmsTime } from "@/utils/index";
var postForm = {
  basicInfo: {
    showEnroll: 1,
    activityId: -1,
    virtualBrowse: "",
    isInvitionCard: 1,
    enroll_at_type: 0,
    l1Ratio: 0,
    l2Ratio: 0,
    audience: "",
    l3Ratio: 0,
    agentRatio: 0,
    partnerRatio: 0,
    branchRatio: 0,
    teacherId: 0,
    teacherRatio: 0,
    state: 0,
    opType: 1,
    refDatum: "",
    name: null,
    place: null,
    sponsor: null,
    poster: [],
    startAt: "",
    endAt: "",
    enrollStartAt: null,
    enrollEndAt: null,
    intro: "",
    hasDatum: -1,
    hasSocial: -1,
    hasExam: -1,
    datumArr: [],
    socialArr: [],
    examArr: [],
    shareTitle: "",
    shareDesc: "",
    existTeacher: 0,
    agentRatio: "",
    agentRatios: "",
    partnerRatio: "",
    partnerRatios: "",
    sharePhoto: ""
  },
  formSetting: {
    aefId: -1, // 表单项id
    activityId: -1, // 活动id
    sort: 0, // 排序
    enabled: 0, // 是否启用
    isReq: 0, // 是否必填
    isMultiline: 0, // 是否多行文本
    fieldNo: null, // 文本框label
    fieldName: null, // 文本框内容
    deleteStatus: 0 // 是否被删除
  },
  ticket: {
    atId: -1,
    name: "",
    activityId: -1,
    number: 0,
    permission: 19,
    price: 0,
    deductiblePoints: 0,
    vipDiscount: 100,
    svipDiscount: 100,
    isAudit: 0,
    purchaseLimits: 0,
    sort: 0,
    status: 0,
    desc: "",
    opType: 1
  },
  related: {
    checked: false,
    fileList: []
  },
  percentage: {
    radio: "1",
    value: "",
    infos: [],
    firstStage: null, // 第一级抽成比例 必填
    secondStage: null, // 第二级抽成比例
    thirdStage: null, // 第三级抽成比例
    agentStage: null, // 代理商抽成比例
    partnerStage: null, // 合伙人抽成比例
    branchStage: null // 分公司抽成比例
  }
};
const isTeacherOptions = [
  // 是否关联讲师
  { key: 1, value: "是" },
  { key: -1, value: "否" }
];
const inviteOptions = [
  { key: 1, value: "是" },
  { key: 0, value: "否" }
];
const rules = {
  name: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
  place: [{ required: true, message: "请输入活动地点", trigger: "blur" }],
  sponsor: [{ required: true, message: "请输入主办方", trigger: "blur" }],
  enrollStartAt: [{ required: true, message: "请输入活动时间" }]
  // signTime: [{required: true}],
  // activityUpload: [{ required: true, validator: validateUpload, trigger: 'submitForm' }]
};

export default {
  components: {
    addRelated,
    VDistpicker,
    Tinymce,
    Multiselect
  },
  props: {
    // 属性
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now();
        }
      },
      finished: false,
      optionsList: [],
      release: 1,
      svipShow: true,
      creditShow: true,
      datumShow: true, // 资料
      socialShow: true, // 社群
      examShow: true, // 测评
      relaShow: true,
      agentLevel: 0,
      permission: 3,
      editChargeTicketData: [],
      relType: "",
      objData: [],
      isShowAddRelated: false,
      hasTeacher: -1,
      isBasicInfo: true,
      isFormSetting: false,
      isTicketSetting: false,
      datumForm: {
        token: null
      },
      poster: [],
      fileName: null,
      datumPostForm: Object.assign({}, postForm),
      encodeUserId: null,
      isAdd: true,
      isChargeTicket: false,
      isFreeTicket: false,
      infos: [],
      deleteInfos: [],
      stage1: [
        { l1Ratio: 0, l2Ratio: 0, l3Ratio: 0 } // 代理商抽成比例
      ],
      stage2: [
        { agentRatio: 0, partnerRatio: 0, branchRatio: 0 } // 代理商抽成比例
      ],
      invitingCard: {
        data1: "",
        data2: "",
        data3: "",
        checked: false
      },
      freeTicketTableData: [],
      ticketTableData: [],
      isAllowNull1: false,
      info1: "",
      defineCode1: "",
      isAllowNull2: false,
      info2: "",
      defineCode2: "",
      postForm: Object.assign({}, postForm),
      rules,
      inviteOptions,
      isInvite: true,
      inviteShow: true,
      formLoading: false,
      btnLoading: false,
      finishLoading: false,
      isTeacherOptions,
      isTeacher: false,
      teacherList: [],
      teacherInfo: [],
      isShowDefineTime: false,
      teacherShow: false,
      syncLoading: false,
      imageUploadUrl: process.env.BASE_API + "/common/activities/imageUpload",
      percent: 0,
      relatedPercent: 0,
      status: "",
      relatedStatus: ""
    };
  },
  created() {
    this.postForm = {
      basicInfo: {
        catId: 1,
        showEnroll: 1,
        virtualBrowse: "",
        activityId: -1,
        audience: "",
        isInvitionCard: 1,
        enroll_at_type: 0,
        l1Ratio: 0,
        l2Ratio: 0,
        l3Ratio: 0,
        agentRatio: 0,
        partnerRatio: 0,
        branchRatio: 0,
        teacherId: 0,
        teacherRatio: 0,
        state: 1,
        opType: 1,
        refDatum: "",
        name: null,
        place: null,
        sponsor: null,
        poster: [],
        startAt: "",
        endAt: "",
        enrollStartAt: null,
        enrollEndAt: null,
        intro: "",
        datumArr: [],
        socialArr: [],
        examArr: [],
        shareTitle: "",
        shareDesc: "",
        sharePhoto: ""
      },
      formSetting: {
        catId: 0,
        aefId: -1, // 表单项id
        activityId: -1, // 活动id
        sort: 0, // 排序
        enabled: 0, // 是否启用
        isReq: 0, // 是否必填
        isMultiline: 0, // 是否多行文本
        fieldNo: null, // 文本框label
        fieldName: null, // 文本框内容
        deleteStatus: 0 // 是否被删除
      },
      ticket: {
        atId: -1,
        name: "",
        activityId: -1,
        number: 0,
        permission: 19,
        price: 0,
        deductiblePoints: 0,
        vipDiscount: 100,
        svipDiscount: 100,
        isAudit: 0,
        sort: 0,
        status: 0,
        purchaseLimits: 0,
        desc: "",
        opType: 1
      },
      related: {
        checked: false,
        fileList: []
      },
      percentage: {
        radio: "1",
        value: "",
        infos: [],
        hasTeacher: -1,
        firstStage: null, // 第一级抽成比例 必填
        secondStage: null, // 第二级抽成比例
        thirdStage: null, // 第三级抽成比例
        agentStage: null, // 代理商抽成比例
        partnerStage: null, // 合伙人抽成比例
        branchStage: null // 分公司抽成比例
      }
    };
  },
  mounted() {
    this.initOptions();
    this.initData();
    this.getTeacher();
    this.deleteInfos = [];
    this.getTicketData();
    this.enableModules();
  },
  watch: {
    // 监听路由名称变化 重新调用数据
    $route: function(to, from) {
      if (to.name == "editActivity") {
        this.initData();
        this.getTeacher();
        this.getFormData();
        this.isAdd = true;
        this.getTicketData();
        if (this.freeTicketTableData.length == 1) {
          this.isAdd = false;
        } else {
          this.isAdd = true;
        }
      }
    }
  },
  methods: {
    initOptions() {
      catList().then(res => {
        this.optionsList = res.data.data;
      });
    },
    setDefultImg(e) {
      e.target.src = defultImg;
    },
    enableModules() {
      if (!enableSvip()) {
        this.svipShow = false;
        this.postForm.ticket.svipDiscount = 0;
      }
      if (!enablePointModule()) {
        this.creditShow = false;
        this.postForm.ticket.deductiblePoints = 0;
      }
      if (!enableDatumModule()) {
        this.datumShow = false;
      }
      if (!enableSocialModule()) {
        this.socialShow = false;
      }
      if (!enableExamModule()) {
        this.examShow = false;
      }
      if (
        !enableExamModule() &&
        !enableDatumModule() &&
        !enableSocialModule()
      ) {
        this.relaShow = false;
      }
      this.agentLevel = getAgentLevels();
      if (this.agentLevel != 3) {
        this.postForm.basicInfo.partnerRatio = 0;
        this.postForm.basicInfo.branchRatio = 0;
      }
    },
    hideAddRelated(msg) {
      this.objData.push(...msg);
      this.isShowAddRelated = false;
    },
    closeAddRelated(msg) {
      this.isShowAddRelated = msg;
    },
    cancelRel(type, index) {
      if (type == 1) {
        this.postForm.basicInfo.datumArr.splice(index, 1);
        this.$forceUpdate();
      } else if (type == 2) {
        this.postForm.basicInfo.socialArr.splice(index, 1);
        this.$forceUpdate();
      } else if (type == 3) {
        this.postForm.basicInfo.examArr.splice(index, 1);
        this.$forceUpdate();
      }
    },
    addRelObj(type, objData) {
      this.relType = type;
      this.objData = objData;
      this.isShowAddRelated = true;
      // this.$refs['related'].getRelData()
    },
    finish() {
      if (this.release == 1) {
        if (
          this.ticketTableData.length == 0 &&
          this.freeTicketTableData.length == 0
        ) {
          this.$message({
            message: "票种必须设置一种",
            type: "warning"
          });
          return;
        }
        this.postForm.basicInfo.opType = 6;
      } else {
        this.postForm.basicInfo.opType = 4;
      }

      this.formLoading = true;
      this.finishLoading = true;
      addOrEditActivities(this.postForm.basicInfo)
        .then(res => {
          this.formLoading = false;
          this.finishLoading = false;
          if (res.data.data.retError == 0) {
            this.$message({
              type: "success",
              message: "保存成功!"
            });
            this.$emit("fresh");
          }
        })
        .catch(error => {
          this.finishLoading = false;
          this.formLoading = false;
          console.log(error);
        });
      this.close();
    },
    close() {
      this.$store.dispatch("delVisitedViews", this.$route).then(views => {
        const latestView = views.slice(-1)[0];

        if (latestView) {
          this.$router.push({ path: "/activities/activities" });
        } else {
          this.$router.push("/");
        }
      });
    },
    initData() {
      if (this.isEdit) {
        this.postForm.basicInfo.activityId = this.$route.params.activityId;
        this.formLoading = true;
        this.postForm.basicInfo.intro = "";
        getActivitiesById(this.postForm.basicInfo)
          .then(res => {
            this.isBasicInfo = true;
            this.isFormSetting = false;
            this.isTicketSetting = false;
            this.postForm.basicInfo = res.data.data.data[0];
            this.postForm.basicInfo.datumArr = res.data.data.datumArr;
            this.postForm.basicInfo.socialArr = res.data.data.socialArr;
            this.postForm.basicInfo.examArr = res.data.data.examArr;
            if (res.data.data.data[0].poster) {
              this.poster = [{ url: res.data.data.data[0].poster }];
            }
            // 是否关联讲师
            if (this.postForm.basicInfo.enroll_at_type == 1) {
              this.isShowDefineTime = true;
            }
            if (
              this.postForm.basicInfo.teacherId != "" &&
              this.postForm.basicInfo.teacherId != null &&
              this.postForm.basicInfo.existTeacher != 0
            ) {
              this.hasTeacher = 1;
              this.teacherShow = true;
              this.postForm.percentage.hasTeacher = 1;
              getMemberSearch(this.postForm.basicInfo.teacherId)
                .then(res => {
                  this.teacherInfo = res.data.data[0];
                })
                .catch(err => {
                  console.log(err);
                });
            } else {
              this.hasTeacher = -1;
              this.teacherShow = false;
              this.teacherRatio = 0;
            }
            // 是否设置课程抽成比例
            if (this.postForm.isCourseCommission) {
              this.courseCommissionShow = true;
            }
            // 获取分销抽成比例

            this.stage1 = [
              {
                l1Ratio: this.postForm.basicInfo.l1Ratio,
                l2Ratio: this.postForm.basicInfo.l2Ratio,
                l3Ratio: this.postForm.basicInfo.l3Ratio
              }
            ];
            // 获取服务商抽成比例
            this.stage2 = [
              {
                agentRatio: this.postForm.basicInfo.agentRatio,
                partnerRatio: this.postForm.basicInfo.partnerRatio,
                branchRatio: this.postForm.basicInfo.branchRatio
              }
            ];
            /* } else {
             this.$message({
             message: '数据获取失败，请稍后再试！',
             type: 'warning'
             })
             }*/
            if (this.postForm.basicInfo.state == 0) {
              this.release = 0;
            } else if (this.postForm.basicInfo.state == 1) {
              this.release = 1;
            } else {
              this.release = 2;
            }
            this.formLoading = false;
          })
          .catch(err => {
            this.formLoading = false;
            console.log(err);
          });
      }
    },
    selectEnrollType(val) {
      // 选择开始报名时间
      if (val == 0) {
        this.isShowDefineTime = false;
      } else {
        this.isShowDefineTime = true;
      }
    },
    selectDatum() {
      this.isSelect = true;
    },
    nextForm() {
      this.getFormData();
      this.isBasicInfo = false;
      this.isFormSetting = true;
    },

    getFormData() {
      if (this.postForm.basicInfo.activityId == -1) {
        return;
      }
      if (this.isEdit) {
        this.postForm.formSetting.activityId = this.$route.params.activityId;
      } else {
        this.postForm.formSetting.activityId = this.postForm.basicInfo.activityId;
      }
      getActivityEnrollFields(this.postForm.formSetting).then(res => {
        this.infos = res.data.data.data;
        // 是否必选
        for (var i in this.infos) {
          if (this.infos[i].isReq == 1) {
            this.infos[i].isReq = true;
          } else {
            this.infos[i].isReq = false;
          }
        }
      });
    },
    backBasicInfo() {
      // 报名表单返回上一步
      this.isBasicInfo = true;
      this.isFormSetting = false;
    },
    nextTicket() {
      // 报名表单下一步
      for (var i in this.infos) {
        if (this.infos[i].isReq == true) {
          this.infos[i].isReq = 1;
        } else {
          this.infos[i].isReq = 0;
        }
        if (this.infos[i].fieldNo == "" || this.infos[i].fieldNo.trim() == "") {
          this.$message("自定义字段第一个文本框信息必填");
          return;
        }
      }
      for (var j in this.deleteInfos) {
        this.infos.push(this.deleteInfos[j]);
      }
      this.deleteInfos = [];
      this.formLoading = true;
      setActivityEnrollFields(this.infos).then(res => {
        this.formLoading = false;
        this.isBasicInfo = false;
        this.isFormSetting = false;
        this.isTicketSetting = true;
      });
      this.getTicketData();
    },
    getTicketData() {
      if (this.isEdit) {
        this.postForm.basicInfo.activityId = this.$route.params.activityId;
      } else {
        // this.postForm.basicInfo.opType = 2
        this.postForm.basicInfo.activityId = this.postForm.formSetting.activityId;
      }
      getActivityTickets(this.postForm.basicInfo).then(res => {
        this.freeTicketTableData = [];
        this.ticketTableData = [];
        this.isAdd = true;
        for (var i = 0; i < res.data.data.data.length; i++) {
          if (res.data.data.data[i].permission == 19) {
            this.freeTicketTableData.push(res.data.data.data[i]);
            this.isAdd = false;
          } else {
            this.ticketTableData.push(res.data.data.data[i]);
          }
        }
      });
    },
    backFormSetting() {
      getActivityEnrollFields(this.postForm.formSetting).then(res => {
        this.infos = res.data.data.data;
        // 是否必选
        for (var i in this.infos) {
          if (this.infos[i].isReq == 1) {
            this.infos[i].isReq = true;
          } else {
            this.infos[i].isReq = false;
          }
        }
      });
      this.isTicketSetting = false;
      this.isFormSetting = true;
    },
    onPublic() {
      if (this.agentLevel != 3) {
        this.postForm.basicInfo.partnerRatio = 0;
        this.postForm.basicInfo.branchRatio = 0;
      }
      if (this.postForm.basicInfo.l1Ratio == 0) {
        if (
          this.postForm.basicInfo.l2Ratio != 0 ||
          this.postForm.basicInfo.l3Ratio != 0
        ) {
          this.$message("一级抽成比例设置为0，二三级也只能为0");
          return;
        }
      }
      if (this.postForm.basicInfo.l2Ratio == 0) {
        if (this.postForm.basicInfo.l3Ratio != 0) {
          this.$message("二级级抽成比例设置为0，三级也只能为0");
          return;
        }
      }
      this.stage1[0].l1Ratio = this.postForm.basicInfo.l1Ratio;
      this.stage1[0].l2Ratio = this.postForm.basicInfo.l2Ratio;
      this.stage1[0].l3Ratio = this.postForm.basicInfo.l3Ratio;
      this.stage2[0].agentRatio = this.postForm.basicInfo.agentRatio;
      this.stage2[0].partnerRatio = this.postForm.basicInfo.partnerRatio;
      this.stage2[0].branchRatio = this.postForm.basicInfo.branchRatio;
      if (
        this.postForm.basicInfo.name == null ||
        this.postForm.basicInfo.name == "" ||
        this.postForm.basicInfo.name.trim() == ""
      ) {
        this.$message("活动名称必填");
        return;
      }
      if (
        this.postForm.basicInfo.place == null ||
        this.postForm.basicInfo.place == "" ||
        this.postForm.basicInfo.place.trim() == ""
      ) {
        this.$message("活动地点必填");
        return;
      }
      if (
        this.postForm.basicInfo.sponsor == null ||
        this.postForm.basicInfo.sponsor == "" ||
        this.postForm.basicInfo.sponsor.trim() == ""
      ) {
        this.$message("活动主办方必填");
        return;
      }
      if (
        parseFloat(this.postForm.basicInfo.l1Ratio) < 0 ||
        parseFloat(this.postForm.basicInfo.l2Ratio) < 0 ||
        parseFloat(this.postForm.basicInfo.l3Ratio) < 0 ||
        parseFloat(this.postForm.basicInfo.agentRatio) < 0 ||
        parseFloat(this.postForm.basicInfo.partnerRatio) < 0 ||
        parseFloat(this.postForm.basicInfo.branchRatio) < 0
      ) {
        this.$message("抽成比例勿小于0");
        return;
      }
      if (this.teacherShow) {
        if (parseFloat(this.postForm.basicInfo.teacherRatio) < 0) {
          this.$message("抽成比例勿小于0");
          return;
        }
        if (
          parseFloat(this.postForm.basicInfo.teacherRatio) +
            parseFloat(this.postForm.basicInfo.l1Ratio) +
            parseFloat(this.postForm.basicInfo.l2Ratio) +
            parseFloat(this.postForm.basicInfo.l3Ratio) +
            parseFloat(this.postForm.basicInfo.agentRatio) +
            parseFloat(this.postForm.basicInfo.partnerRatio) +
            parseFloat(this.postForm.basicInfo.branchRatio) >
          100
        ) {
          this.$message("抽成比例总和勿大于100%");
          return;
        }
      } else {
        if (
          parseFloat(this.postForm.basicInfo.l1Ratio) +
            parseFloat(this.postForm.basicInfo.l2Ratio) +
            parseFloat(this.postForm.basicInfo.l3Ratio) +
            parseFloat(this.postForm.basicInfo.agentRatio) +
            parseFloat(this.postForm.basicInfo.partnerRatio) +
            parseFloat(this.postForm.basicInfo.branchRatio) >
          100
        ) {
          this.$message("抽成比例总和勿大于100%");
          return;
        }
      }
      // if (this.teacherInfo) {
      //   this.postForm.basicInfo.teacherId = this.teacherInfo.userId;
      // }
      // if (this.hasTeacher == -1) {
      //   this.postForm.basicInfo.teacherId = null;
      // }
      // if (this.hasTeacher == 1) {
      //   if (
      //     this.teacherInfo.length == 0 ||
      //     this.postForm.basicInfo.teacherRatio == ""
      //   ) {
      //     this.$message("关联了收益人必须选择收益人跟抽成比例");
      //     return;
      //   }
      // }
      this.$refs.basicInfo.validate(valid => {
        if (valid) {
          /** 创建活动基本信息*/
          if (
            this.postForm.basicInfo.startAt == "" ||
            this.postForm.basicInfo.startAt == null ||
            this.postForm.basicInfo.endAt == "" ||
            this.postForm.basicInfo.endAt == null
          ) {
            this.$message({
              message: "活动开始跟结束时间必填!",
              type: "warning"
            });
            return;
          }
          if (this.postForm.basicInfo.enroll_at_type == 1) {
            if (
              this.postForm.basicInfo.startAt > this.postForm.basicInfo.endAt
            ) {
              this.$message({
                message: "报名结束时间要大于报名开始时间!",
                type: "warning"
              });
              return;
            }
          }
          if (this.postForm.basicInfo.enroll_at_type == 1) {
            if (
              this.postForm.basicInfo.endAt <
              this.postForm.basicInfo.enrollEndAt
            ) {
              this.$message({
                message: "活动结束时间要大于活动报名结束时间!",
                type: "warning"
              });
              return;
            }
          }
          if (
            this.postForm.basicInfo.enrollStartAt >
            this.postForm.basicInfo.enrollEndAt
          ) {
            this.$message({
              message: "活动结束时间要大于活动开始时间!",
              type: "warning"
            });
            return;
          }
          if (this.postForm.basicInfo.enrollEndAt < getYmdhmsTime(new Date())) {
            this.$message({
              message: "活动结束时间不能小于当前时间!",
              type: "warning"
            });
            return;
          }
          // console.log(this.isShowDefineTime, this.postForm.basicInfo.startAt, this.postForm.basicInfo.endAt)
          if (
            this.isShowDefineTime &&
            !this.postForm.basicInfo.startAt &&
            !this.postForm.basicInfo.endAt
          ) {
            this.$message({
              message: "报名时间必填，不能为空!",
              type: "warning"
            });
            return;
          }
          if (this.postForm.basicInfo.poster.length == 0) {
            this.postForm.basicInfo.poster = "";
          }
          // this.postForm.basicInfo.state = 0
          this.formLoading = true;
          if (this.btnLoading) {
            return;
          }
          this.btnLoading = true;
          addOrEditActivities(this.postForm.basicInfo)
            .then(res => {
              this.formLoading = false;
              this.btnLoading = false;
              // 新增完则返回活动ID，更新操作返回null
              if (res.data.data.retActivityId != null) {
                this.postForm.basicInfo.activityId =
                  res.data.data.retActivityId;
              }
              // 新增完数据，变插入为更新操作
              if (this.postForm.basicInfo.activityId != -1) {
                this.postForm.basicInfo.opType = 2;
              }
              if (res.data.data.retError != 0) {
                this.$message("活动创建流程失败，请联系管理员");
              } else {
                this.nextForm();
              }
            })
            .catch(err => {
              this.btnLoading = false;
              this.formLoading = false;
            });
        }
      });
    },
    inviteSelect() {},

    // 上传海报开始
    submitActivityUpload() {
      this.$refs.activityUpload.submit();
    },
    handleActivitySuccess(response, file, fileList) {
      if (response.statusCode == 200) {
        this.postForm.basicInfo.poster = response.data.imageUrl;
        this.$message({
          message: "上传成功!",
          type: "info"
        });
      } else {
        this.$message({
          message: "上传失败，请稍候再试!",
          type: "info"
        });
      }
    },
    handleActivitySuccesss(response, file, fileList) {
      if (response.statusCode == 200) {
        this.postForm.basicInfo.sharePhoto = response.data.imageUrl;
        this.$message({
          message: "上传成功!",
          type: "info"
        });
      } else {
        this.$message({
          message: "上传失败，请稍候再试!",
          type: "info"
        });
      }
    },
    handleActivityRemoves(file, fileList) {
      this.postForm.basicInfo.sharePhoto = null;
    },
    handleActivityRemove(file, fileList) {
      this.postForm.basicInfo.poster = null;
    },
    handleBeforeUpload(file) {
      const isImg = file.type == "image/jpeg" || file.type == "image/png";
      const isLt3M = file.size / 1024 / 1024 < 3;
      if (!isImg) {
        this.$message.warning("上传图片只能是 JPG 或 PNG 格式");
      }
      if (!isLt3M) {
        this.$message({
          message: "上传文件大小不能超过3MB!",
          type: "warning"
        });
      }
      return isImg && isLt3M;
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `共上传了${files.length +
          fileList.length} 个文件，当前限制 1 个文件，请先清除文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    addSingle() {
      for (var i in this.infos) {
        if (this.infos[i].fieldNo == "" || this.infos[i].fieldNo.trim() == "") {
          this.$message({
            message:
              "请先填写好当前自定义字段的第一个文本信息才能再添加单行文本哦",
            type: "warning"
          });
          return;
        }
      }
      // 添加单行文本
      this.infos.push({
        aefId: -1,
        activityId: this.postForm.basicInfo.activityId,
        sort: 0, // 排序
        enabled: 1, // 是否启用
        isMultiline: 0,
        isReq: 0,
        fieldNo: "",
        fieldName: "",
        deleteStatus: 0 // 是否被删除
      });
    },
    addMultiline() {
      for (var i in this.infos) {
        if (this.infos[i].fieldNo == "" || this.infos[i].fieldNo.trim() == "") {
          this.$message({
            message:
              "请先填写好当前自定义字段的第一个文本信息才能再添加多行行文本哦",
            type: "warning"
          });
          return;
        }
      }
      // 添加多行
      this.infos.push({
        aefId: -1,
        activityId: this.postForm.basicInfo.activityId,
        sort: 0, // 排序
        enabled: 1, // 是否启用
        isMultiline: 1,
        isReq: 0,
        fieldNo: "",
        fieldName: "",
        deleteStatus: 0 // 是否被删除
      });
    },
    delInfo(index) {
      // 删除表单自定义字段
      this.infos[index].deleteStatus = 1;
      this.deleteInfos.push(this.infos[index]);
      this.infos.splice(index, 1);
    },
    emptyForm() {
      this.postForm.ticket = {
        atId: -1,
        name: "",
        activityId: -1,
        number: 0,
        permission: 19,
        price: 0,
        deductiblePoints: 0,
        vipDiscount: 100,
        svipDiscount: 100,
        isAudit: 0,
        sort: 0,
        status: 0,
        desc: "",
        opType: 1
      };
    },
    addFreeTicket() {
      if (this.isChargeTicket) {
        this.$message({
          message: "请先把收费票填完再添加免费票哦",
          type: "warning"
        });
        return;
      }
      this.emptyForm();
      this.isFreeTicket = true;
      this.isAdd = false;
    },
    conserveFreeTickeData() {
      if (
        this.postForm.ticket.name == "" ||
        this.postForm.ticket.name.trim() == ""
      ) {
        this.$message({
          message: "票名称不能为空",
          type: "warning"
        });
        return;
      }
      if (this.postForm.ticket.number <= 0) {
        this.$message({
          message: "票总数应该大于0",
          type: "warning"
        });
        return;
      }
      this.postForm.ticket.activityId = this.postForm.basicInfo.activityId;
      if (this.postForm.ticket.atId != -1) {
        this.postForm.ticket.opType = 2;
      }
      this.postForm.ticket.isAudit =
        this.postForm.ticket.isAudit == true ? 1 : 0;
      this.formLoading = true;
      setActivityTickets(this.postForm.ticket)
        .then(res => {
          this.formLoading = false;
          this.getTicketData();
        })
        .catch(err => {
          this.formLoading = false;
          console.log(err);
        });

      this.isFreeTicket = false;
      this.isAdd = false;
    },
    delFreeTicketData() {
      if (this.isChargeTicket) {
        this.$message({
          message: "请先编辑完或者取消收费票再删除免费票",
          type: "warning"
        });
        return;
      }
      this.$confirm("此操作将删除该票务, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.postForm.ticket = {
          atId: this.freeTicketTableData[0].atId,
          name: this.freeTicketTableData[0].name,
          activityId: this.freeTicketTableData[0].activityId,
          number: this.freeTicketTableData[0].number,
          permission: 19,
          price: 0,
          deductiblePoints: 0,
          vipDiscount: 0,
          svipDiscount: 0,
          isAudit: 0,
          sort: 0,
          status: 0,
          desc: this.freeTicketTableData[0].desc,
          opType: 3
        };
        setActivityTickets(this.postForm.ticket).then(res => {
          this.$message({
            message: "删除成功",
            type: "warning"
          });
          this.getTicketData();
          this.isAdd = true;
        });
      });
    },
    addChargeTicket() {
      if (this.isFreeTicket) {
        this.$message({
          message: "请先把免费票填完再添加收费票哦",
          type: "warning"
        });
        return;
      }
      this.emptyForm();
      this.postForm.ticket.permission = 18;
      this.isChargeTicket = true;
    },
    conserveChargeData() {
      if (
        this.postForm.ticket.name == "" ||
        this.postForm.ticket.name.trim() == ""
      ) {
        this.$message({
          message: "票名称不能为空",
          type: "warning"
        });
        return;
      }
      if (
        parseFloat(this.postForm.ticket.vipDiscount) < 0 ||
        parseFloat(this.postForm.ticket.svipDiscount) < 0
      ) {
        this.$message({
          message: "折扣不能小于0",
          type: "warning"
        });
        return;
      }

      if (
        parseFloat(this.postForm.ticket.vipDiscount) > 100 ||
        parseFloat(this.postForm.ticket.vipDiscount) > 100
      ) {
        this.$message({
          message: "折扣不能大于100",
          type: "warning"
        });
        return;
      }
      if (this.svipShow) {
        if (
          parseFloat(this.postForm.ticket.vipDiscount) <
          parseFloat(this.postForm.ticket.svipDiscount)
        ) {
          this.$message({
            message: "超级会员折扣应该大于会员折扣",
            type: "warning"
          });
          return;
        }
      } else {
        this.postForm.ticket.svipDiscount = this.postForm.ticket.vipDiscount;
      }
      if (
        parseFloat(this.postForm.ticket.number) <= 0 ||
        parseFloat(this.postForm.ticket.price) <= 0
      ) {
        this.$message({
          message: "票总数跟价格应该大于0",
          type: "warning"
        });
        return;
      }
      if (this.creditShow) {
        if (
          parseFloat(this.postForm.ticket.deductiblePoints) >
          parseFloat(this.postForm.ticket.price)
        ) {
          this.$message({
            message: "积分抵扣金额不能大于票价",
            type: "warning"
          });
          return;
        }
      } else {
        this.postForm.ticket.deductiblePoints = 0;
      }
      if (this.postForm.ticket.atId != -1) {
        this.postForm.ticket.opType = 2;
      }
      this.postForm.ticket.permission = 18;
      this.postForm.ticket.activityId = this.postForm.basicInfo.activityId;
      this.formLoading = true;
      setActivityTickets(this.postForm.ticket)
        .then(res => {
          this.formLoading = false;
          this.getTicketData();
        })
        .catch(err => {
          this.formLoading = false;
          console.log(err);
        });

      this.isChargeTicket = false;
    },
    delChargeTicketData(index) {
      if (this.isChargeTicket || this.isFreeTicket) {
        this.$message({
          message: "请先保存或者取消上一条编辑再删除票务",
          type: "warning"
        });
        return;
      }
      this.postForm.ticket = {
        atId: this.ticketTableData[index].atId,
        name: this.ticketTableData[index].name,
        activityId: this.ticketTableData[index].activityId,
        number: this.ticketTableData[index].number,
        permission: this.ticketTableData[index].permission,
        price: this.ticketTableData[index].price,
        deductiblePoints: this.ticketTableData[index].deductiblePoints,
        vipDiscount: this.ticketTableData[index].vipDiscount,
        svipDiscount: this.ticketTableData[index].svipDiscount,
        isAudit: 0,
        sort: 0,
        status: 0,
        desc: this.ticketTableData[index].desc,
        opType: 3
      };

      this.$confirm("此操作将删除该票务, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        setActivityTickets(this.postForm.ticket).then(res => {
          this.$message({
            message: "删除成功",
            type: "warning"
          });
          this.ticketTableData.splice(index, 1);
        });
      });
    },

    // 讲师收益的处理代码
    isTeacherSelect(val) {
      if (val == 1) {
        this.teacherShow = true;
        this.teacherInfo = [];
        this.postForm.basicInfo.teacherRatio = 0;
      } else {
        this.teacherShow = false;
        this.teacherInfo = [];
        this.postForm.basicInfo.teacherRatio = 0;
      }
    },
    teacherOptionSelect(selectedOption, id) {
      this.postForm.basicInfo.teacherId = selectedOption.userId;
    },
    getTeacher() {
      initMemberList()
        .then(res => {
          const resData = res.data.data;
          this.teacherList = [];
          for (let i = 0; i < resData.length; i++) {
            this.teacherList.push({
              userId: resData[i].userId,
              nickname:
                resData[i].nickname + `（ID: ${resData[i].encodeUserId}）`
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    syncSearchTeachers(query) {
      this.syncLoading = true;
      getMemberSearch(query)
        .then(res => {
          this.syncLoading = false;
          const resData = res.data.data;
          this.teacherList = [];
          for (let i = 0; i < resData.length; i++) {
            this.teacherList.push({
              userId: resData[i].userId,
              nickname:
                resData[i].nickname + `（ID: ${resData[i].encodeUserId}）`
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    editTick(index) {
      if (this.isFreeTicket) {
        this.$message({
          message: "请先保存或者取消免费票编辑再点收费票编辑",
          type: "warning"
        });
        return;
      }
      if (this.isChargeTicket) {
        this.$message({
          message: "请先保存或者取消上一条编辑再点下一条编辑",
          type: "warning"
        });
        return;
      }
      this.isChargeTicket = true;
      this.postForm.ticket.atId = this.ticketTableData[index].atId;
      this.postForm.ticket.purchaseLimits = this.ticketTableData[
        index
      ].purchaseLimits;
      this.postForm.ticket.desc = this.ticketTableData[index].desc;
      this.postForm.ticket.taoTicket = this.ticketTableData[index].taoTicket;
      this.postForm.ticket.activityId = this.ticketTableData[index].activityId;
      this.postForm.ticket.status = this.ticketTableData[index].status;
      this.postForm.ticket.name = this.ticketTableData[index].name;
      this.postForm.ticket.price = this.ticketTableData[index].price;
      this.postForm.ticket.number = this.ticketTableData[index].number;
      this.postForm.ticket.deductiblePoints = this.ticketTableData[
        index
      ].deductiblePoints;
      this.postForm.ticket.permission = this.ticketTableData[index].permission;
      this.postForm.ticket.vipDiscount = this.ticketTableData[
        index
      ].vipDiscount;
      this.postForm.ticket.svipDiscount = this.ticketTableData[
        index
      ].svipDiscount;
      this.editChargeTicketData.push(this.ticketTableData.splice(index, 1));
    },
    editFreeTicket(index) {
      if (this.isChargeTicket) {
        this.$message({
          message: "请先编辑完或者取消收费票再删除免费票",
          type: "warning"
        });
        return;
      }
      this.isFreeTicket = true;
      this.postForm.ticket.atId = this.freeTicketTableData[index].atId;
      this.postForm.ticket.taoTicket = this.freeTicketTableData[
        index
      ].taoTicket;
      this.postForm.ticket.purchaseLimits = this.freeTicketTableData[
        index
      ].purchaseLimits;
      this.postForm.ticket.desc = this.freeTicketTableData[index].desc;
      this.postForm.ticket.activityId = this.freeTicketTableData[
        index
      ].activityId;
      this.postForm.ticket.name = this.freeTicketTableData[index].name;
      this.postForm.ticket.price = this.freeTicketTableData[index].price;
      this.postForm.ticket.number = this.freeTicketTableData[index].number;
      this.postForm.ticket.deductiblePoints = this.freeTicketTableData[
        index
      ].deductiblePoints;
      this.postForm.ticket.permission = this.freeTicketTableData[
        index
      ].permission;
      this.postForm.ticket.vipDiscount = this.freeTicketTableData[
        index
      ].vipDiscount;
      this.postForm.ticket.svipDiscount = this.freeTicketTableData[
        index
      ].svipDiscount;
      this.postForm.ticket.isAudit =
        this.freeTicketTableData[index].isAudit == 1;
      this.freeTicketTableData.splice(index, 1);
    },
    delFreeTicketForm() {
      this.isFreeTicket = false;
      if (this.postForm.ticket.atId != -1) {
        this.conserveFreeTickeData();
      }
      if (this.freeTicketTableData.length == 0) {
        this.isAdd = true;
      }
    },
    delChargeTicketForm() {
      if (this.postForm.ticket.atId != -1) {
        this.conserveChargeData();
      }
      this.isChargeTicket = false;
    },
    saveRelated() {}
  }
};
</script>

